class Room < ActiveRecord::Base
  validates_uniqueness_of :name
  validates_presence_of :name
  
  has_many :computers, :dependent => :destroy do 
    def incidents_not_resolved
      find :all, :joins => "INNER JOIN incidents ON incidents.computer_id = computers.id AND incidents.resolved_at IS NULL"
    end
  end
  
  def incidents_not_resolved
    computers.incidents_not_resolved
  end
  
  def incidents_not_resolved?
    !computers.incidents_not_resolved.empty?
  end
end
